package com.jwds.digital.bios.business.service.service.belt.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwds.digital.bios.business.core.infrastructure.dto.feign.FlowBasicReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.entity.belt.*;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.FlowBasicRespVO;
import com.jwds.digital.bios.business.core.utils.FeignResultUtil;
import com.jwds.digital.bios.business.rpc.feign.FlowBasicFeign;
import com.jwds.digital.bios.business.service.service.belt.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>BeltCoreHandleServiceImpl 皮带云核心路线处理类</p>
 *
 * @author 李志明
 */
@Service
public class BeltCoreHandleLineServiceImpl implements BeltCoreHandleLineService {
    @Autowired
    IBeltPerformanceMinuteService iBeltPerformanceMinuteService;

    @Autowired
    IBeltPerformanceHourService beltPerformanceHourService;

    @Autowired
    IBeltRoutePerformanceHourService beltRoutePerformanceHourService;


    @Autowired
    IBeltRoutePerformanceDayService beltRoutePerformanceDayService;

    @Autowired
    IBeltRoutePerformanceWeekService beltRoutePerformanceWeekService;

    @Autowired
    IBeltRoutePerformanceMonthService beltRoutePerformanceMonthService;

    @Autowired
    FlowBasicFeign flowBasicFeign;

    /**
     * 根据皮带效能一分钟数据计算一小时的皮带效能数据
     *
     * @param startTime
     * @param endTime
     */
    public void doOneHourCalculateByOneMinData(String startTime, String endTime) {
// 解析开始时间和结束时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startDateTime = LocalDateTime.parse(startTime, formatter);
        LocalDateTime endDateTime = LocalDateTime.parse(endTime, formatter);
        //找出一小时内所有皮带的一分钟数据
        List<BeltPerformanceMinute> minuteDataList = iBeltPerformanceMinuteService
                .list(new LambdaQueryWrapper<BeltPerformanceMinute>()
                        .ge(BeltPerformanceMinute::getStartTime, startTime)
                        .le(BeltPerformanceMinute::getEndTime, endTime)
                );
        // 按照线路id分组
        Map<Short, List<BeltPerformanceMinute>> minuteDataMap = minuteDataList.stream().collect(
                Collectors.groupingBy(BeltPerformanceMinute::getFlowNo));
        // 遍历每条线路，统计一小时的数据
        minuteDataMap.forEach((flowNo, minuteDataListByBelt) -> {
            // 对每条线路的数据根据 startTime 进行排序
            List<BeltPerformanceMinute> sortedData = minuteDataListByBelt.stream()
                    .sorted(Comparator.comparing(BeltPerformanceMinute::getStartTime))
                    .collect(Collectors.toList());
            // 第一条数据开始时间
            LocalDateTime firstRecord = sortedData.get(0).getStartTime();
            // 最后一条数据结束时间
            LocalDateTime lastRecord = sortedData.get(sortedData.size() - 1).getEndTime();
            // 第一次空载到负载转换开始和结束时间
            LocalDateTime first0To1 = null;
            LocalDateTime first0To2 = null;
            // 最后一次负载到空载转换开始时间和结束时间
            LocalDateTime last1To0 = null;
            LocalDateTime last1To1 = null;
            // 启动空载电耗
            BigDecimal startEmptyLoad;
            // 停止空载电耗
            BigDecimal stopEmptyLoad;
            // 初始化为-1，确保第一个元素可以被检查
            int previousLoadStatus = -1;
            for (BeltPerformanceMinute record : sortedData) {
                int currentLoadStatus = record.getLoadStatus();

                if (previousLoadStatus == 0 && currentLoadStatus == 1 && first0To1 == null) {
                    // 第一次发现从0到1的变化
                    first0To1 = record.getStartTime();
                    first0To2 = record.getEndTime();
                } else if (previousLoadStatus == 1 && currentLoadStatus == 0) {
                    // 每次遇到从1到0的变化都更新last1To0
                    last1To0 = record.getStartTime();
                    last1To1 = record.getEndTime();
                }

                previousLoadStatus = currentLoadStatus;
            }
            LocalDateTime finalFirst0To = first0To1;//空载到负载转换结束时间
            LocalDateTime finalFirst0To2 = first0To2;
            LocalDateTime finalLast1To0 = last1To0;
            LocalDateTime finalLast1To1 = last1To1;
            // 查询并获取第一条数据到空负载转换区间的数据
            if (Objects.nonNull(first0To1)) {

                List<BeltPerformanceMinute> intervalData = sortedData.stream()
                        .filter(record -> !record.getStartTime().isAfter(firstRecord)
                                && !record.getEndTime().isBefore(finalFirst0To))
                        .collect(Collectors.toList());

                // 累加intervalData中所有记录的powerConsumption值
                startEmptyLoad = intervalData.stream()
                        .map(BeltPerformanceMinute::getPowerConsumption)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
            } else {
                startEmptyLoad = BigDecimal.ZERO;
            }

            // 查询并获取最后一条数据到负空载转换区间的数据
            if (Objects.nonNull(last1To0)) {

                List<BeltPerformanceMinute> intervalData = sortedData.stream()
                        .filter(record -> !record.getStartTime().isAfter(finalLast1To0)
                                && !record.getEndTime().isBefore(lastRecord))
                        .collect(Collectors.toList());
                // 累加intervalData中所有记录的powerConsumption值
                stopEmptyLoad = intervalData.stream()
                        .map(BeltPerformanceMinute::getPowerConsumption)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
            } else {
                stopEmptyLoad = BigDecimal.ZERO;
            }
            // 按照作业任务分组
            Map<Long, List<BeltPerformanceMinute>> minuteAndTaskDataMap = minuteDataListByBelt.stream().collect(Collectors.groupingBy(BeltPerformanceMinute::getTaskId));
            minuteAndTaskDataMap.forEach((taskId, minuteDataListByTask) -> {
                //查出每一条线路有多少皮带
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setFlowNo(minuteDataListByTask.stream().findFirst().get().getFlowNo());
                List<FlowBasicRespVO> FlowBasicList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                String flowCode = FlowBasicList.stream().findFirst().get().getFlowCode();
                // 通过下划线进行切割
                String[] flowCodeList = flowCode.split("-");
                BeltRoutePerformanceHour beltRoutePerformanceHour = new BeltRoutePerformanceHour();
                List<BeltPerformanceMinute> oneMinLoadList = minuteDataListByBelt.stream().filter(minuteData -> minuteData.getLoadStatus() == 1).collect(Collectors.toList());
                List<BeltPerformanceMinute> oneMinUnLoadList = minuteDataListByBelt.stream().filter(minuteData -> minuteData.getLoadStatus() == 0).collect(Collectors.toList());
                // 负载时长、空载时长
                int oneHourLoadRunningTime = new BigDecimal(oneMinLoadList.stream().mapToInt(BeltPerformanceMinute::getRuntime).sum()).divide(BigDecimal.valueOf(flowCodeList.length), 2, RoundingMode.HALF_UP).intValue();
                int oneHourUnLoadRunningTime = new BigDecimal(oneMinUnLoadList.stream().mapToInt(BeltPerformanceMinute::getRuntime).sum()).divide(BigDecimal.valueOf(flowCodeList.length), 2, RoundingMode.HALF_UP).intValue();
                // 计算总运行时间
                BigDecimal allRuntime = BigDecimal.valueOf(oneHourLoadRunningTime + oneHourUnLoadRunningTime);
                // 负载 平均负载率
                BigDecimal avgLoadRate = oneMinLoadList.stream().map(BeltPerformanceMinute::getAvgLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(oneMinLoadList.size()), 2, RoundingMode.HALF_UP).divide(BigDecimal.valueOf(flowCodeList.length), 2, RoundingMode.HALF_UP);
                beltRoutePerformanceHour.setAvgLoadRate(avgLoadRate);
                // 空载 平均负载率
                BigDecimal avgNoLoadRate = oneMinUnLoadList.stream().map(BeltPerformanceMinute::getAvgLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(oneMinLoadList.size()), 2, RoundingMode.HALF_UP).divide(BigDecimal.valueOf(flowCodeList.length), 2, RoundingMode.HALF_UP);
                beltRoutePerformanceHour.setAvgNoLoadRate(avgNoLoadRate);
                // 负载率占比
                BigDecimal hourLoadRatio = BigDecimal.valueOf(oneHourLoadRunningTime / (oneHourUnLoadRunningTime + oneHourLoadRunningTime)).setScale(2, RoundingMode.HALF_UP);
                beltRoutePerformanceHour.setLoadRateRatio(hourLoadRatio);

                // 计算作业率
                BigDecimal totalRunningTime = BigDecimal.valueOf(oneHourLoadRunningTime + oneHourUnLoadRunningTime);
                if (totalRunningTime.compareTo(BigDecimal.ZERO) > 0) {
                    BigDecimal workRate = BigDecimal.valueOf(oneHourLoadRunningTime).divide(totalRunningTime, 2, RoundingMode.HALF_UP);
                    beltRoutePerformanceHour.setWorkRate(workRate);
                } else {
                    beltRoutePerformanceHour.setWorkRate(BigDecimal.ZERO);
                }

                // 计算作业效率
                if (oneHourLoadRunningTime > 0 && !oneMinLoadList.isEmpty()) {
                    BigDecimal workEfficiency = avgLoadRate.divide(BigDecimal.valueOf(oneHourLoadRunningTime), 4, RoundingMode.HALF_UP);
                    beltRoutePerformanceHour.setWorkEfficiency(workEfficiency);
                } else {
                    beltRoutePerformanceHour.setWorkEfficiency(BigDecimal.ZERO);
                }


                // 所有电耗、负载电耗、空载电耗
                BigDecimal totalPowerConsumption = minuteDataListByTask.stream().map(BeltPerformanceMinute::getPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal loadPowerConsumption = oneMinLoadList.stream().map(BeltPerformanceMinute::getPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal oneHourUnLoadPowerConsumption = oneMinUnLoadList.stream().map(BeltPerformanceMinute::getPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);


                // 计算平均电机运行效率
                BigDecimal averageMotorOperatingEfficiency = totalPowerConsumption.compareTo(BigDecimal.ZERO) == 0
                        ? BigDecimal.ZERO
                        : loadPowerConsumption.divide(totalPowerConsumption, 4, BigDecimal.ROUND_HALF_UP);
                // 将运行效率转换为等级
                int efficiencyLevel = 0;
                if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.9")) >= 0) {
                    efficiencyLevel = 0; // 极高
                } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.7")) >= 0) {
                    efficiencyLevel = 1; // 高
                } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.6")) >= 0) {
                    efficiencyLevel = 2; // 较高
                } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.5")) >= 0) {
                    efficiencyLevel = 3; // 较低
                } else {
                    efficiencyLevel = 4; // 低
                }
                // 设置运行效率
                beltRoutePerformanceHour.setAverageMotorOperatingEfficiency(efficiencyLevel);
                // 峰谷平尖电耗
                BigDecimal spikePowerConsumption = minuteDataListByTask.stream()
                        .filter(record -> record.getPowerType() == 1)
                        .map(BeltPerformanceMinute::getPowerConsumption)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal peakPowerConsumption = minuteDataListByTask.stream()
                        .filter(record -> record.getPowerType() == 2)
                        .map(BeltPerformanceMinute::getPowerConsumption)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal valleyPowerConsumption = minuteDataListByTask.stream()
                        .filter(record -> record.getPowerType() == 4)
                        .map(BeltPerformanceMinute::getPowerConsumption)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal flatPowerConsumption = minuteDataListByTask.stream()
                        .filter(record -> record.getPowerType() == 3)
                        .map(BeltPerformanceMinute::getPowerConsumption)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);
                // 计算运输量
                BigDecimal totalTransport = minuteDataListByTask.stream()
                        .map(BeltPerformanceMinute::getTotalTransport)
                        .filter(Objects::nonNull)
                        .reduce(BigDecimal.ZERO, BigDecimal::add);


                // 计算运行效率
                BigDecimal operationEfficiency = minuteDataListByTask.stream()
                        .map(BeltPerformanceMinute::getOperationEfficiency)
                        .filter(Objects::nonNull)
                        .reduce(BigDecimal.ZERO, BigDecimal::add)
                        .divide(BigDecimal.valueOf(minuteDataListByTask.size()), 4, BigDecimal.ROUND_HALF_UP);

                beltRoutePerformanceHour.setAllRuntime(allRuntime);
                // 设置 belong_date 字段
                beltRoutePerformanceHour.setBelongDate(startDateTime.toLocalDate());
                // 启动空载电耗,停止空载电耗
                beltRoutePerformanceHour.setStartNoLoadPowerConsumption(startEmptyLoad);
                beltRoutePerformanceHour.setEndNoLoadPowerConsumption(stopEmptyLoad);
                // 负载运行时间，空载运行时间
                beltRoutePerformanceHour.setLoadRuntime(BigDecimal.valueOf(oneHourLoadRunningTime / 3600).setScale(2, RoundingMode.HALF_UP));
                beltRoutePerformanceHour.setNoLoadRuntime(BigDecimal.valueOf(oneHourUnLoadRunningTime / 3600).setScale(2, RoundingMode.HALF_UP));
//                    beltRoutePerformanceHour.setStartTime(LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//                    beltRoutePerformanceHour.setEndTime(LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                // 启动空载开始时间,启动空载结束时间
                beltRoutePerformanceHour.setStartTime(firstRecord);
                beltRoutePerformanceHour.setEndTime(lastRecord);
                // 停止空载开始时间,停止空载结束时间
                beltRoutePerformanceHour.setStartNoLoadStartTime(firstRecord);
                beltRoutePerformanceHour.setEndNoLoadStartTime(finalFirst0To);
                beltRoutePerformanceHour.setStartEmptyTime(finalLast1To0);
                beltRoutePerformanceHour.setEndEmptyTime(lastRecord);
                /*beltRoutePerformanceHour.setStartEmptyTime(lastRecord);
                beltRoutePerformanceHour.setEndEmptyTime(finalLast1To0);*/
                beltRoutePerformanceHour.setTotalPowerConsumption(totalPowerConsumption);
                beltRoutePerformanceHour.setLoadPowerConsumption(loadPowerConsumption);
                beltRoutePerformanceHour.setNoLoadPowerConsumption(oneHourUnLoadPowerConsumption);
                // 峰谷平尖电耗
                beltRoutePerformanceHour.setSpikePowerConsumption(spikePowerConsumption);
                beltRoutePerformanceHour.setPeakPowerConsumption(peakPowerConsumption);
                beltRoutePerformanceHour.setValleyPowerConsumption(valleyPowerConsumption);
                beltRoutePerformanceHour.setFlatPowerConsumption(flatPowerConsumption);
                beltRoutePerformanceHour.setRouteId(Long.valueOf(minuteDataListByBelt.get(0).getFlowNo()));
                beltRoutePerformanceHour.setTotalTransport(totalTransport);
                beltRoutePerformanceHour.setOperationEfficiency(operationEfficiency);
                beltRoutePerformanceHour.setIsDeleted(0);
                beltRoutePerformanceHourService.save(beltRoutePerformanceHour);
            });
        });
    }
    /**
     * 根据线路效能一小时数据计算一天的线路效能数据
     *
     * @param startTime
     * @param endTime
     */
    public void doOneHourLineCalculateByOneDayData(String startTime, String endTime) {

        //找出一周内所有皮带的一小时数据
        List<BeltRoutePerformanceHour> hourDataList = beltRoutePerformanceHourService
                .list(new LambdaQueryWrapper<BeltRoutePerformanceHour>()
                        .ge(BeltRoutePerformanceHour::getStartTime, startTime)
                        .le(BeltRoutePerformanceHour::getEndTime, endTime)
                );
       /* //找出一周内所有皮带的一小时数据
        List<BeltRoutePerformanceHour> hourDataList = beltRoutePerformanceHourService
                .list(new LambdaQueryWrapper<BeltRoutePerformanceHour>()
                        .ge(BeltRoutePerformanceHour::getCreateTime, startTime)
                        .le(BeltRoutePerformanceHour::getCreateTime, endTime)
                );*/
        // 按照线路id分组
        Map<Long, List<BeltRoutePerformanceHour>> hourDataMap = hourDataList.stream().collect(
                Collectors.groupingBy(BeltRoutePerformanceHour::getRouteId));
        // 遍历每条线路，统计一小时的数据
        hourDataMap.forEach((beltId, HourDataListByLine) -> {
            // 按开始时间进行排序
            HourDataListByLine.sort(Comparator.comparing(BeltRoutePerformanceHour::getStartTime));

            if (HourDataListByLine.isEmpty()) {
                return; // 如果没有数据，跳过
            }

            // 获取第一条和最后一条数据
            BeltRoutePerformanceHour firstHourData = HourDataListByLine.get(0);
            BeltRoutePerformanceHour lastHourData = HourDataListByLine.get(HourDataListByLine.size() - 1);

            // 获取第一条和最后一条数据的时间
            LocalDateTime firstTimestamp = firstHourData.getStartTime();
            LocalDateTime lastTimestamp = firstHourData.getEndTime();

            BeltRoutePerformanceDay beltRoutePerformanceDay = new BeltRoutePerformanceDay();
            // 负载率、空负载率
            BigDecimal oneDayAvgLoadRate = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getAvgLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(HourDataListByLine.size()), 0, RoundingMode.HALF_UP);
            BigDecimal oneDayAvgNoLoadRate = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getAvgNoLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(HourDataListByLine.size()), 0, RoundingMode.HALF_UP);
            // 负载时长、空载时长
            BigDecimal oneDayLoadRunningTime = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getLoadRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneDayUnLoadRunningTime = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getNoLoadRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneDayAllRunningTime = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getAllRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            // 负载率占比
            BigDecimal oneDayLoadRateProportion = oneDayLoadRunningTime.divide(oneDayAllRunningTime, 2, RoundingMode.HALF_UP);
            // 总电耗、负载电耗、空载电耗
            BigDecimal oneDayAllPowerConsumption = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getTotalPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneDayLoadPowerConsumption = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getLoadPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneDayUnLoadPowerConsumption = HourDataListByLine.stream().map(BeltRoutePerformanceHour::getNoLoadPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);


            // 启动空载电耗、停止空载电耗
            BigDecimal oneDayStartNoLoadPowerConsumption = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getStartNoLoadPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal oneDayEndNoLoadPowerConsumption = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getEndNoLoadPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            // 计算平均电机运行效率
            BigDecimal averageMotorOperatingEfficiency = oneDayAllPowerConsumption.compareTo(BigDecimal.ZERO) == 0
                    ? BigDecimal.ZERO
                    : oneDayAllPowerConsumption.divide(oneDayLoadPowerConsumption, 4, BigDecimal.ROUND_HALF_UP);
            // 将运行效率转换为等级
            int efficiencyLevel = 0;
            if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.9")) >= 0) {
                efficiencyLevel = 0; // 极高
            } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.7")) >= 0) {
                efficiencyLevel = 1; // 高
            } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.6")) >= 0) {
                efficiencyLevel = 2; // 较高
            } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.5")) >= 0) {
                efficiencyLevel = 3; // 较低
            } else {
                efficiencyLevel = 4; // 低
            }
            // 设置运行效率
            beltRoutePerformanceDay.setAverageMotorOperatingEfficiency(efficiencyLevel);
            // 作业率
            BigDecimal workRate = oneDayLoadRunningTime.divide(oneDayAllRunningTime, 4, RoundingMode.HALF_UP);

            // 峰谷平尖电耗
            BigDecimal spikePowerConsumption = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getSpikePowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal peakPowerConsumption = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getPeakPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal valleyPowerConsumption = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getValleyPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal flatPowerConsumption = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getFlatPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            //运输量
            BigDecimal totalTransport = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getTotalTransport)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            //作业效率
            BigDecimal workEfficiency = oneDayAllPowerConsumption.compareTo(BigDecimal.ZERO) == 0
                    ? BigDecimal.ZERO
                    : totalTransport.divide(oneDayAllPowerConsumption, 4, RoundingMode.HALF_UP);
            //运行效率
            BigDecimal operationEfficiency = HourDataListByLine.stream()
                    .map(BeltRoutePerformanceHour::getOperationEfficiency)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add)
                    .divide(BigDecimal.valueOf(HourDataListByLine.size()), 4, BigDecimal.ROUND_HALF_UP);
            LocalDateTime startDateTime = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            beltRoutePerformanceDay.setBelongDate(startDateTime.toLocalDate());
            LocalDateTime startEmptyTime = lastHourData.getStartTime();
            LocalDateTime endEmptyTime = lastHourData.getEndTime();
            beltRoutePerformanceDay.setStartEmptyTime(startEmptyTime);
            beltRoutePerformanceDay.setEndEmptyTime(endEmptyTime);
            beltRoutePerformanceDay.setStartTime(firstTimestamp);
            beltRoutePerformanceDay.setEndTime(lastTimestamp);
            beltRoutePerformanceDay.setRouteId(HourDataListByLine.get(0).getRouteId());
            beltRoutePerformanceDay.setAvgLoadRate(oneDayAvgLoadRate);
            beltRoutePerformanceDay.setAvgNoLoadRate(oneDayAvgNoLoadRate);
            beltRoutePerformanceDay.setLoadRateRatio(oneDayLoadRateProportion);
            beltRoutePerformanceDay.setNoLoadPowerConsumption(oneDayUnLoadPowerConsumption);
            beltRoutePerformanceDay.setLoadPowerConsumption(oneDayLoadPowerConsumption);
            beltRoutePerformanceDay.setTotalPowerConsumption(oneDayAllPowerConsumption);
            beltRoutePerformanceDay.setNoLoadRuntime(oneDayUnLoadRunningTime);
            //beltRoutePerformanceDay.setOperationEfficiency(averageMotorOperatingEfficiency);
            beltRoutePerformanceDay.setOperationEfficiency(operationEfficiency);
            beltRoutePerformanceDay.setLoadRuntime(oneDayLoadRunningTime);
            beltRoutePerformanceDay.setAllRuntime(oneDayAllRunningTime);
            beltRoutePerformanceDay.setStartTime(firstHourData.getStartNoLoadStartTime());
            beltRoutePerformanceDay.setEndTime(firstHourData.getEndNoLoadStartTime());
            beltRoutePerformanceDay.setWorkRate(workRate);
            beltRoutePerformanceDay.setPeakPowerConsumption(peakPowerConsumption);
            beltRoutePerformanceDay.setValleyPowerConsumption(valleyPowerConsumption);
            beltRoutePerformanceDay.setFlatPowerConsumption(flatPowerConsumption);
            beltRoutePerformanceDay.setSpikePowerConsumption(spikePowerConsumption);
            beltRoutePerformanceDay.setWorkEfficiency(workEfficiency);
            beltRoutePerformanceDay.setTotalTransport(totalTransport);
            beltRoutePerformanceDay.setStartNoLoadPowerConsumption(oneDayStartNoLoadPowerConsumption);
            beltRoutePerformanceDay.setEndNoLoadPowerConsumption(oneDayEndNoLoadPowerConsumption);
            beltRoutePerformanceDay.setIsDeleted(0);
            beltRoutePerformanceDayService.save(beltRoutePerformanceDay);
        });
    }

    /**
     * 根据线路效能日数据计算周级别的线路效能数据
     *
     * @param startTime
     * @param endTime
     */
    public void doOneWeekLineCalculateByOneDayData(String startTime, String endTime) {
        //找出一周内所有线路的日数据
        List<BeltRoutePerformanceDay> dayDataList = beltRoutePerformanceDayService
                .list(new LambdaQueryWrapper<BeltRoutePerformanceDay>()
                        .ge(BeltRoutePerformanceDay::getCreateTime, startTime)
                        .le(BeltRoutePerformanceDay::getCreateTime, endTime)
                );
        /*//找出一周内所有线路的日数据
        List<BeltRoutePerformanceDay> dayDataList = beltRoutePerformanceDayService
                .list(new LambdaQueryWrapper<BeltRoutePerformanceDay>()
                        .ge(BeltRoutePerformanceDay::getStartTime, startTime)
                        .le(BeltRoutePerformanceDay::getEndTime, endTime)
                );*/
        // 按照线路id分组
        Map<Long, List<BeltRoutePerformanceDay>> dayDataMap = dayDataList.stream().collect(
                Collectors.groupingBy(BeltRoutePerformanceDay::getRouteId));
        dayDataMap.forEach((beltId, dayDataListByLine) -> {
            // 按开始时间进行排序
            dayDataListByLine.sort(Comparator.comparing(BeltRoutePerformanceDay::getStartTime));

            if (dayDataListByLine.isEmpty()) {
                return; // 如果没有数据，跳过
            }

            // 获取第一条和最后一条数据
            BeltRoutePerformanceDay firstDayData = dayDataListByLine.get(0);
            BeltRoutePerformanceDay lastDayData = dayDataListByLine.get(dayDataListByLine.size() - 1);

            // 获取第一条和最后一条数据的时间
            LocalDateTime firstTimestamp = firstDayData.getStartTime();
            LocalDateTime lastTimestamp = firstDayData.getEndTime();

            BeltRoutePerformanceWeek beltRoutePerformanceWeek = new BeltRoutePerformanceWeek();
            // 负载率、空负载率
            BigDecimal oneWeekAvgLoadRate = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getAvgLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(dayDataListByLine.size()), 0, RoundingMode.HALF_UP);
            BigDecimal oneWeekAvgNoLoadRate = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getAvgNoLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(dayDataListByLine.size()), 0, RoundingMode.HALF_UP);
            // 负载时长、空载时长
            BigDecimal oneWeekLoadRunningTime = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getLoadRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekUnLoadRunningTime = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getNoLoadRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekAllRunningTime = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getAllRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            // 负载率占比
            BigDecimal oneWeekLoadRateProportion = oneWeekLoadRunningTime.divide(oneWeekAllRunningTime, 2, RoundingMode.HALF_UP);
            // 总电耗、负载电耗、空载电耗
            BigDecimal oneWeekAllPowerConsumption = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getTotalPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekLoadPowerConsumption = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getLoadPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekUnLoadPowerConsumption = dayDataListByLine.stream().map(BeltRoutePerformanceDay::getNoLoadPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            // 启动空载电耗、停止空载电耗
            BigDecimal startNoLoadPowerConsumption = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getStartNoLoadPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal endNoLoadPowerConsumption = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getEndNoLoadPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            // 计算平均电机运行效率
            BigDecimal averageMotorOperatingEfficiency = oneWeekAllPowerConsumption.compareTo(BigDecimal.ZERO) == 0
                    ? BigDecimal.ZERO
                    : oneWeekAllPowerConsumption.divide(oneWeekLoadPowerConsumption, 4, BigDecimal.ROUND_HALF_UP);
            // 将运行效率转换为等级
            int efficiencyLevel = 0;
            if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.9")) >= 0) {
                efficiencyLevel = 0; // 极高
            } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.7")) >= 0) {
                efficiencyLevel = 1; // 高
            } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.6")) >= 0) {
                efficiencyLevel = 2; // 较高
            } else if (averageMotorOperatingEfficiency.compareTo(new BigDecimal("0.5")) >= 0) {
                efficiencyLevel = 3; // 较低
            } else {
                efficiencyLevel = 4; // 低
            }
            // 设置运行效率
            beltRoutePerformanceWeek.setAverageMotorOperatingEfficiency(efficiencyLevel);

            // 作业率：负载运行时间 / 总运行时间
            BigDecimal workRate = oneWeekAllRunningTime.compareTo(BigDecimal.ZERO) == 0
                    ? BigDecimal.ZERO
                    : oneWeekLoadRunningTime.divide(oneWeekAllRunningTime, 4, RoundingMode.HALF_UP);

            // 作业效率：运输量 / 总耗电量
            BigDecimal totalTransport = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getTotalTransport)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal workEfficiency = oneWeekAllPowerConsumption.compareTo(BigDecimal.ZERO) == 0
                    ? BigDecimal.ZERO
                    : totalTransport.divide(oneWeekAllPowerConsumption, 4, RoundingMode.HALF_UP);

            // 峰谷平尖电耗
            BigDecimal spikePowerConsumption = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getSpikePowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal peakPowerConsumption = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getPeakPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal valleyPowerConsumption = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getValleyPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal flatPowerConsumption = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getFlatPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal operationEfficiency = dayDataListByLine.stream()
                    .map(BeltRoutePerformanceDay::getOperationEfficiency)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add)
                    .divide(BigDecimal.valueOf(dayDataListByLine.size()), 4, BigDecimal.ROUND_HALF_UP);

// 设置 belong_date 字段
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

            beltRoutePerformanceWeek.setBelongDate(LocalDateTime.parse(startTime, formatter).toLocalDate());
            beltRoutePerformanceWeek.setRouteId(dayDataListByLine.get(0).getRouteId());
            beltRoutePerformanceWeek.setAvgLoadRate(oneWeekAvgLoadRate);
            beltRoutePerformanceWeek.setAvgNoLoadRate(oneWeekAvgNoLoadRate);
            beltRoutePerformanceWeek.setLoadRateRatio(oneWeekLoadRateProportion);
            beltRoutePerformanceWeek.setWorkRate(workRate);
            beltRoutePerformanceWeek.setWorkEfficiency(workEfficiency);
            beltRoutePerformanceWeek.setTotalTransport(totalTransport);
            // beltRoutePerformanceWeek.setOperationEfficiency(averageMotorOperatingEfficiency);
            beltRoutePerformanceWeek.setOperationEfficiency(operationEfficiency);
            beltRoutePerformanceWeek.setNoLoadPowerConsumption(oneWeekUnLoadPowerConsumption);
            beltRoutePerformanceWeek.setLoadPowerConsumption(oneWeekLoadPowerConsumption);
            beltRoutePerformanceWeek.setStartNoLoadPowerConsumption(startNoLoadPowerConsumption);
            beltRoutePerformanceWeek.setEndNoLoadPowerConsumption(endNoLoadPowerConsumption);
            beltRoutePerformanceWeek.setNoLoadRuntime(oneWeekUnLoadRunningTime);
            beltRoutePerformanceWeek.setLoadRuntime(oneWeekLoadRunningTime);
            beltRoutePerformanceWeek.setSpikePowerConsumption(spikePowerConsumption);
            beltRoutePerformanceWeek.setPeakPowerConsumption(peakPowerConsumption);
            beltRoutePerformanceWeek.setValleyPowerConsumption(valleyPowerConsumption);
            beltRoutePerformanceWeek.setFlatPowerConsumption(flatPowerConsumption);
            beltRoutePerformanceWeek.setTotalPowerConsumption(oneWeekAllPowerConsumption);
            beltRoutePerformanceWeek.setAllRuntime(oneWeekAllRunningTime);
            beltRoutePerformanceWeek.setStartTime(firstTimestamp);
            beltRoutePerformanceWeek.setEndTime(firstDayData.getEndTime());
            beltRoutePerformanceWeek.setStartEmptyTime(lastDayData.getStartEmptyTime());
            beltRoutePerformanceWeek.setEndEmptyTime(lastDayData.getEndEmptyTime());
            /*beltRoutePerformanceWeek.setStartTime(LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            beltRoutePerformanceWeek.setEndTime(LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));*/
            beltRoutePerformanceWeek.setIsDeleted(0);
            beltRoutePerformanceWeekService.save(beltRoutePerformanceWeek);
        });
    }

    /**
     * 根据线路效能周级别数据计算月级别的线路效能数据
     *
     * @param startTime
     * @param endTime
     */
    public void doOneMonthLineCalculateByOneWeekData(String startTime, String endTime) {
        //找出一月内所有线路的周数据
        List<BeltRoutePerformanceWeek> weekDataList = beltRoutePerformanceWeekService
                .list(new LambdaQueryWrapper<BeltRoutePerformanceWeek>()
                        .ge(BeltRoutePerformanceWeek::getCreateTime, startTime)
                        .le(BeltRoutePerformanceWeek::getCreateTime, endTime)
                );
       /* //找出一月内所有线路的周数据
        List<BeltRoutePerformanceWeek> weekDataList = beltRoutePerformanceWeekService
                .list(new LambdaQueryWrapper<BeltRoutePerformanceWeek>()
                        .ge(BeltRoutePerformanceWeek::getStartTime, startTime)
                        .le(BeltRoutePerformanceWeek::getEndTime, endTime)
                );*/
        // 按照线路id分组
        Map<Long, List<BeltRoutePerformanceWeek>> weekDataMap = weekDataList.stream().collect(
                Collectors.groupingBy(BeltRoutePerformanceWeek::getRouteId));
        weekDataMap.forEach((beltId, weekDataListByLine) -> {
            // 按开始时间进行排序
            weekDataListByLine.sort(Comparator.comparing(BeltRoutePerformanceWeek::getStartTime));

            if (weekDataListByLine.isEmpty()) {
                return; // 如果没有数据，跳过
            }

            // 获取第一条和最后一条数据
            BeltRoutePerformanceWeek firstWeekData = weekDataListByLine.get(0);
            BeltRoutePerformanceWeek lastWeekData = weekDataListByLine.get(weekDataListByLine.size() - 1);

            // 获取第一条和最后一条数据的时间
            LocalDateTime firstTimestamp = firstWeekData.getStartTime();
            LocalDateTime lastTimestamp = lastWeekData.getEndTime();
            BeltRoutePerformanceMonth beltRoutePerformanceMonth = new BeltRoutePerformanceMonth();
            // 负载率、空负载率
            BigDecimal oneWeekAvgLoadRate = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getAvgLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(weekDataListByLine.size()), 0, RoundingMode.HALF_UP);
            BigDecimal oneWeekAvgNoLoadRate = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getAvgNoLoadRate).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(weekDataListByLine.size()), 0, RoundingMode.HALF_UP);
            // 负载时长、空载时长
            BigDecimal oneWeekLoadRunningTime = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getLoadRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekUnLoadRunningTime = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getNoLoadRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekAllRunningTime = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getAllRuntime).reduce(BigDecimal.ZERO, BigDecimal::add);
            // 负载率占比
            BigDecimal oneWeekLoadRateProportion = oneWeekLoadRunningTime.divide(oneWeekAllRunningTime, 2, RoundingMode.HALF_UP);
            // 总电耗、负载电耗、空载电耗
            BigDecimal oneWeekAllPowerConsumption = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getTotalPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekLoadPowerConsumption = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getLoadPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal oneWeekUnLoadPowerConsumption = weekDataListByLine.stream().map(BeltRoutePerformanceWeek::getNoLoadPowerConsumption).reduce(BigDecimal.ZERO, BigDecimal::add);

            // 计算启动和停止时的空载电耗
            BigDecimal oneWeekStartNoLoadPowerConsumption = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getStartNoLoadPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal oneWeekEndNoLoadPowerConsumption = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getEndNoLoadPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            // 尖峰、峰值、谷值、平值耗电量
            BigDecimal oneWeekSpikePowerConsumption = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getSpikePowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal oneWeekPeakPowerConsumption = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getPeakPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal oneWeekValleyPowerConsumption = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getValleyPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            BigDecimal oneWeekFlatPowerConsumption = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getFlatPowerConsumption)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            // 运输量
            BigDecimal oneWeekTotalTransport = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getTotalTransport)
                    .reduce(BigDecimal.ZERO, BigDecimal::add);

            // 计算作业率和作业效率
            BigDecimal oneWeekWorkRate = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getWorkRate)
                    .reduce(BigDecimal.ZERO, BigDecimal::add)
                    .divide(BigDecimal.valueOf(weekDataListByLine.size()), 4, RoundingMode.HALF_UP);

            BigDecimal oneWeekWorkEfficiency = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getWorkEfficiency)
                    .reduce(BigDecimal.ZERO, BigDecimal::add)
                    .divide(BigDecimal.valueOf(weekDataListByLine.size()), 4, RoundingMode.HALF_UP);
            // 计算运行效率
            BigDecimal averageMotorOperatingEfficiency = weekDataListByLine.stream()
                    .map(BeltRoutePerformanceWeek::getOperationEfficiency)
                    .filter(Objects::nonNull)
                    .reduce(BigDecimal.ZERO, BigDecimal::add)
                    .divide(BigDecimal.valueOf(weekDataListByLine.size()), 4, BigDecimal.ROUND_HALF_UP);
            // 计算平均运行效率
            BigDecimal operationEfficiency = oneWeekAllPowerConsumption.compareTo(BigDecimal.ZERO) == 0
                    ? BigDecimal.ZERO
                    : oneWeekLoadPowerConsumption.divide(oneWeekAllPowerConsumption, 4, RoundingMode.HALF_UP);

            // 将运行效率转换为等级
            int efficiencyLevel = 0;
            if (operationEfficiency.compareTo(new BigDecimal("0.9")) >= 0) {
                efficiencyLevel = 0; // 极高
            } else if (operationEfficiency.compareTo(new BigDecimal("0.7")) >= 0) {
                efficiencyLevel = 1; // 高
            } else if (operationEfficiency.compareTo(new BigDecimal("0.6")) >= 0) {
                efficiencyLevel = 2; // 较高
            } else if (operationEfficiency.compareTo(new BigDecimal("0.5")) >= 0) {
                efficiencyLevel = 3; // 较低
            } else {
                efficiencyLevel = 4; // 低
            }
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

            beltRoutePerformanceMonth.setBelongDate(LocalDateTime.parse(startTime, formatter).toLocalDate());
            beltRoutePerformanceMonth.setStartTime(firstWeekData.getStartTime());
            beltRoutePerformanceMonth.setEndTime(firstWeekData.getEndTime());
            beltRoutePerformanceMonth.setStartEmptyTime(lastWeekData.getStartEmptyTime());
            beltRoutePerformanceMonth.setEndEmptyTime(lastWeekData.getEndEmptyTime());
            beltRoutePerformanceMonth.setRouteId(beltId);
            beltRoutePerformanceMonth.setOperationEfficiency(averageMotorOperatingEfficiency);
            beltRoutePerformanceMonth.setAvgLoadRate(oneWeekAvgLoadRate);
            beltRoutePerformanceMonth.setAvgNoLoadRate(oneWeekAvgNoLoadRate);
            beltRoutePerformanceMonth.setLoadRateRatio(oneWeekLoadRateProportion);
            beltRoutePerformanceMonth.setWorkRate(oneWeekWorkRate);
            beltRoutePerformanceMonth.setWorkEfficiency(oneWeekWorkEfficiency);
            beltRoutePerformanceMonth.setNoLoadPowerConsumption(oneWeekUnLoadPowerConsumption);
            beltRoutePerformanceMonth.setLoadPowerConsumption(oneWeekLoadPowerConsumption);
            beltRoutePerformanceMonth.setStartNoLoadPowerConsumption(oneWeekStartNoLoadPowerConsumption);
            beltRoutePerformanceMonth.setEndNoLoadPowerConsumption(oneWeekEndNoLoadPowerConsumption);
            beltRoutePerformanceMonth.setNoLoadRuntime(oneWeekUnLoadRunningTime);
            beltRoutePerformanceMonth.setLoadRuntime(oneWeekLoadRunningTime);
            beltRoutePerformanceMonth.setTotalTransport(oneWeekTotalTransport);
            beltRoutePerformanceMonth.setSpikePowerConsumption(oneWeekSpikePowerConsumption);
            beltRoutePerformanceMonth.setPeakPowerConsumption(oneWeekPeakPowerConsumption);
            beltRoutePerformanceMonth.setValleyPowerConsumption(oneWeekValleyPowerConsumption);
            beltRoutePerformanceMonth.setFlatPowerConsumption(oneWeekFlatPowerConsumption);
            beltRoutePerformanceMonth.setTotalPowerConsumption(oneWeekAllPowerConsumption);
            beltRoutePerformanceMonth.setIsDeleted(0);

            //beltRoutePerformanceMonth.setAllRuntime(oneWeekAllRunningTime);
            beltRoutePerformanceMonthService.save(beltRoutePerformanceMonth);
        });
    }
}
